import 'package:environmental_les_app/common/net/net.dart';
import 'package:environmental_les_app/common/routes/route_names.dart';
import 'package:environmental_les_app/common/utils/sp_util.dart';
import 'package:flutter_clx_base/flutter_clx_base.dart';
import 'package:flutter_clx_base/widget/normal_dialog.dart';

class MineController extends GetxController {
  MineController();

  _initData() {
    update(["mine"]);
  }

  // 用户信息
  Map<String, dynamic> userInfo = {};

  // 刷新
  void onRefresh() {
    _getUserInfo();
  }

  // @override
  // void onInit() {
  //   super.onInit();
  // }

  // 退出登录
  void logout() {
    Get.dialog(NormalDialog(
      title: "退出登录",
      content: "是否确认退出登录？",
      onConfirm: () {
        NetUtils.post(
          ServiceApi.logout,
          data: null,
          successCallback: (data) {
            logoutRemove();
            Get.offAllNamed(AppRoutes.loginPage);
          },
        );
      },
    ));
  }

  _getUserInfo() {
    NetUtils.post(
      ServiceApi.getUserInfo,
      data: null,
      successCallback: (data) {
        userInfo = data ?? {};
        _initData();
      },
    );
  }

  @override
  void onReady() {
    super.onReady();
    _getUserInfo();
    _initData();
  }

  // @override
  // void onClose() {
  //   super.onClose();
  // }
}
